package com.todo.event.activity.iface.backend.request;

import com.todo.common.common.entity.CurrentStaff;
import com.todo.common.utils.StringUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/1/10 22:03
 * @description
 */
@Data
@Schema(title = "更新事件详情请求参数", description = "更新事件详情请求参数")
public class UpdateEventDetailReq {

private CurrentStaff _staff;


    @Schema(title = "主键id", description = "主键id")
    private Long id;

    @Schema(title = "事件code", description = "事件code")
    private String eventCode;

    @Schema(title = "业务线", description = "业务线")
    private Integer businessLine;

    @Schema(title = "事件基础信息", description = "事件基础信息")
    private EventInfo eventInfo;

    @Schema(title = "事件字段配置", description = "事件字段配置")
    private List<EventField> eventFieldList;

    public boolean baseCheck() {
        if (id == null || StringUtils.isBlank(eventCode) || businessLine == null || eventInfo == null || CollectionUtils.isEmpty(eventFieldList)){
            return false;
        }
        if (eventInfo.eventClassify == null || eventInfo.eventType == null || eventInfo.eventName == null || eventInfo.topicName == null){
            return false;
        }
        for (EventField eventField : eventFieldList){
            if (eventField.dataSource == null || eventField.transfer == null || StringUtils.isBlank(eventField.fieldName) || eventField.fieldType == null){
                return false;
            }
            if (eventField.output && CollectionUtils.isEmpty(eventField.selectOperate)){
                return false;
            }
        }
        return true;
    }


    @Data
    public static class EventInfo {

        @Schema(title = "事件分类", description = "事件分类")
        private Integer eventClassify;

        @Schema(title = "事件类型", description = "事件类型")
        private Integer eventType;

        @Schema(title = "事件名称", description = "事件名称")
        private String eventName;

        @Schema(title = "事件主题", description = "事件主题")
        private String topicName;

        @Schema(title = "tag", description = "tag")
        private String tag;

        @Schema(title = "消费者名称", description = "消费者名称")
        private String consumerName;

        @Schema(title = "队列类型", description = "队列类型")
        private Integer queueType;

        @Schema(title = "事件规则", description = "事件规则")
        private String rule;
    }

    @Data
    public static class EventField {

        @Schema(title = "数据来源", description = "数据来源 代码配置、消息获取、静态数值···")
        private Integer dataSource;

        @Schema(title = "转换方式", description = "转换方式 根据数据来源做策略")
        private String transfer;

        @Schema(title = "字段名称", description = "字段名称")
        private String fieldName;

        @Schema(title = "字段类型", description = "字段类型")
        private Integer fieldType;

        @Schema(title = "字段长度", description = "字段长度")
        private Integer fieldLength;

        @Schema(title = "字段描述", description = "字段描述")
        private String fieldDesc;

        @Schema(title = "是否唯一", description = "是否唯一")
        private Boolean uniqueField;

        @Schema(title = "是否供外部选择", description = "是否供外部选择")
        private Boolean output;

        @Schema(title = "选择操符", description = "选择操符")
        private List<Integer> selectOperate;

        @Schema(title = "选择类型", description = "选择类型 枚举、自定义")
        private Integer selectType;

        @Schema(title = "枚举值", description = "枚举值 selectType = enums 时有值")
        private List<EnumValue> enumsValue;
    }

    @Data
    public static class EnumValue {

        @Schema(title = "key", description = "key")
        private String key;

        @Schema(title = "描述", description = "描述")
        private String desc;
    }
}
